const http = require('http');
const io = require('socket.io');

const app = http.createServer();

app.listen(3000,()=>{
    console.log('running on port 3000');
});

let wsServer = io.listen(app);

wsServer.on('connection',(sock)=>{

    // 服务端接收
    /* sock.on('d',(n,m)=>{
        console.log('客户端传递的' + n + '' + m);
    }); */

    // 服务端发送数据
    setInterval(() => {
        sock.emit('d',Math.random());
    }, 1000);
})